grammar SimpleCalc;



/*
<?xml version="1.0" encoding="UTF-8"?>
<bdiagram1:Diagram xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:bdiagram1="http://bdiagram1/1.0">
  <sensors Name="sensor123"/>
</bdiagram1:Diagram>
*/


tokens {
	SEMI_COL 	= ';' ;
	SENSOR_TAG	= 'sensors' ;
	ACTUATOR_TAG	= 'actuators' ;
	BEHAVIOUR_TAG	= 'behaviours' ;
	NAME_TAG = 'Name="' ;
	OPEN_TAG = '<' ;
	CLOSE_TAG_with_quote = '"/>';
	XML_HEADER_TAG1 = '<?xml version="1.0" encoding="UTF-8"?>';
	XML_HEADER_TAG2_PART2 = ':Diagram xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:';
	XML_HEADER_TAG2_PART3 = '="http://';
	XML_HEADER_TAG2_PART4 = '/1.0">';
	DIAGRAM_TAG = ':Diagram';
	END_CLOSING_TAG = '</';
	CLOSE_TAG = '>';
}


@header {
//import simplecalcparser.datastructures.types.*;
}


@members { 	    
    public static void main(String[] args) throws Exception {
        
        SimpleCalcLexer lex = new SimpleCalcLexer(new ANTLRFileStream(args[0]));
       	CommonTokenStream tokens = new CommonTokenStream(lex);

        SimpleCalcParser parser = new SimpleCalcParser(tokens);

        try {
            parser.fichier_xmi();
        } catch (RecognitionException e)  {
            e.printStackTrace();
        }
    }
}

/*------------------------------------------------------------------
 * PARSER RULES
 *------------------------------------------------------------------*/
 
fichier_xmi : XML_HEADER_TAG1
	      OPEN_TAG name XML_HEADER_TAG2_PART2 name XML_HEADER_TAG2_PART3 name XML_HEADER_TAG2_PART4
	      sensor
	      END_CLOSING_TAG NAME DIAGRAM_TAG CLOSE_TAG
	      {
		// code to do after parsing
	      };

/*
  description_diagram returns [String value] :
  	 	ALL_CHARS_NAME {$value = $ALL_CHARS_NAME.text;}; //ALL_CHARS_NAME
*/

sensor : 	OPEN_TAG SENSOR_TAG WHITESPACE NAME_TAG name CLOSE_TAG_with_quote
		{
			//add_sensor($name.value);
			System.out.println("Sensor name is : " + $name.value);
		}
	 	;

name returns [String value] :
	    NAME {$value = $NAME.text;};

behaviour : 	OPEN_TAG BEHAVIOUR_TAG ' ' NAME_TAG name CLOSE_TAG
		{System.out.println("behaviour name is : " + $name.value);}
		/* generalize this to support several names */
	 	;

actuator : 	OPEN_TAG ACTUATOR_TAG ' ' NAME_TAG name CLOSE_TAG
		{System.out.println("actuator name is : " + $name.value);}
		/* generalize this to support several names */
	 	;

/*------------------------------------------------------------------
 * LEXER RULES
 *------------------------------------------------------------------*/

/* Cela supprime tous les Espaces */
WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+ 	{ $channel = HIDDEN; } ;

NAME : ('a'..'z' | 'A'..'Z' | DIGIT)+;

fragment DIGIT	: '0'..'9' ;

